#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
const int MOD = 1e9+7;
const int inv2 = (MOD + 1)/2;
struct node{
    int x,v;
    friend bool operator<(node va,node vb){
        return va.x < vb.x;
    }
} nds[N];
int nums[N],ncnt;
struct segment_tree{
    int mi[N<<2];
    void build(int now,int l,int r){
        if(l == r){
            mi[now] = 0x3f3f3f3f;
            return;
        }
        int mid = (l + r)/2;
        build(now<<1,l,mid);
        build(now<<1|1,mid+1,r);
        mi[now] = min(mi[now<<1],mi[now<<1|1]);
    }
    void update(int now,int l,int r,int p,int v)
    {
        if(l == r){
            mi[now] = min(mi[now],v);
            return;
        }
        int mid = (l + r)/2;
        if(p <= mid){
            update(now<<1,l,mid,p,v);
        }else{
            update(now<<1|1,mid+1,r,p,v);
        }
        mi[now] = min(mi[now<<1],mi[now<<1|1]);
    }
    int query(int now,int l,int r,int x,int y){
        if(x <= l && r<= y){
            return mi[now];
        }
        int mid = (l + r)/2;
        int res = 0x3f3f3f3f;
        if(x <= mid){
            res = min(res,query(now<<1,l,mid,x,y));
        }
        if(mid < y){
            res = min(res,query(now<<1|1,mid+1,r,x,y));
        }
        return res;
    }

} sg1,sg2;
struct segment_tree1{
    int sum[N<<2];
    void push_up(int now){
        sum[now] = (sum[now<<1] + sum[now<<1|1])%MOD;
    }
    void update(int now,int l,int r,int p,int v){
        if(l == r){
            sum[now] = (sum[now] + v)%MOD;
            return;
        }
        int mid = (l + r)/2;
        if(p <= mid){
            update(now<<1,l,mid,p,v);
        }else{
            update(now<<1|1,mid+1,r,p,v);
        }
        push_up(now);
    }
    int query(int now,int l,int r,int x,int y){
        if(x <= l && r <= y){
            return sum[now];
        }
        int mid = (l + r)/2;
        int su = 0;
        if(x <= mid){
            su = (su + query(now<<1,l,mid,x,y))%MOD;
        }
        if(mid < y){
            su = (su + query(now<<1|1,mid+1,r,x,y))%MOD;
        }
        return su;
    }
}sg3,sg4;
int L[N],R[N];
bool cmp1(pair<int,int> p1,pair<int,int> p2){
    return p1.first < p2.first || p1.first == p2.first && p1.second > p2.second;
}
bool cmp2(pair<int,int> p1,pair<int,int> p2){
    return p1.second < p2.second;
}
pair<int,int> S[N];
int sp;
int dp[N];
int qpow(int x,int p){
    int res = 1;
    while(p){
        if(p & 1){
            res = 1ll*res*x%MOD;
        }
        x = 1ll*x*x%MOD;
        p >>= 1;
    }
    return res;
}
int main(){
    int n;
    cin>>n;
    for(int i = 1;i<=n;i++)
    {
        cin>>nds[i].x>>nds[i].v;
        nums[++ncnt] = nds[i].v;
    }
    sort(nds + 1,nds + 1 + n);
    sort(nums + 1,nums + 1 + ncnt);
    ncnt = unique(nums + 1,nums + 1 + ncnt) - nums - 1;
    for(int i = 1;i <= n;i++){
        nds[i].v = lower_bound(nums + 1,nums + 1 + ncnt,nds[i].v) - nums;
    }
    sg1.build(1,1,ncnt);
    for(int i = 1;i <= n;i++){
        sg1.update(1,1,ncnt,nds[i].v,i);
        L[i] = sg1.query(1,1,ncnt,nds[i].v,ncnt);
    }
    sg2.build(1,1,ncnt);
    for(int i = n;i>=1;i--){
        sg2.update(1,1,ncnt,nds[i].v,n - i);
        R[i] = n - sg2.query(1,1,ncnt,1,nds[i].v);
    }
    vector<pair<int,int>> ps;
    for(int i = 1;i<=n;i++){
        ps.push_back(make_pair(L[i],R[i]));
    }
    sort(ps.begin(),ps.end(),cmp1);
    for(pair<int,int> p : ps){
        while(sp && S[sp].second >= p.second){
            sp--;
        }
        S[++sp] = p;
    }
    sort(S + 1,S + 1 + sp,cmp2);
    /*
    dp[0] = 1;
    for(int i = 1;i<=sp;i++){
        for(int j = 0;j < i;j++){
            if(S[j].second < S[i].first){
                dp[i] = (dp[i] + MOD - 1ll*dp[j]*qpow(inv2,S[i].second - S[i].first + 1)%MOD)%MOD;
            }else{
                dp[i] = (dp[i] + MOD - 1ll*dp[j]*qpow(inv2,S[i].second - S[j].second)%MOD)%MOD;
            }
        }
    }
    */
    dp[0] = 1;
    sg3.update(1,0,sp,0,1);
    sg4.update(1,0,sp,0,1);
    for(int i = 1;i <= sp;i++){
        int l = 0,r = i - 1;
        int cur = 0;
        while(l <= r){
            int mid = (l + r)/2;
            if(S[mid].second < S[i].first){
                cur = mid;
                l = mid + 1;
            }else{
                r = mid - 1;
            }
        }
        dp[i] = (MOD - 1ll*sg3.query(1,0,sp,0,cur)*qpow(inv2,S[i].second - S[i].first + 1)%MOD)%MOD;
        dp[i] = (dp[i] + MOD - 1ll*sg4.query(1,0,sp,cur + 1,i)*qpow(inv2,S[i].second)%MOD)%MOD;
        sg3.update(1,0,sp,i,dp[i]);
        sg4.update(1,0,sp,i,1ll*dp[i]*qpow(2,S[i].second)%MOD);
    }
    int res = 0;
    for(int i = 0;i <= sp;i++){
        res = (res + dp[i])%MOD;
    }
    dp[sp] = 1ll*res*qpow(2,n)%MOD;
    cout<<dp[sp]<<'\n';
}